//
//  JYSearchHistoryView.m
//  JYFarm
//
//  Created by 花花 on 2017/10/20.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYSearchHistoryView.h"

@interface JYSearchHistoryView()

@property(nonatomic)UILabel *searchHistoryLabel; //搜索历史

@property(nonatomic)UIButton *searchHistoryBtn; //清空
@end
@implementation JYSearchHistoryView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self == [super initWithFrame:frame]) {
        
        
        [self setupSubView];
    }
    
    return self;

}
- (void)setupSubView{
    
    [self addSubview:self.searchHistoryLabel];
    
    [self addSubview:self.searchHistoryBtn];

    [self addSubview:self.noHistoryLablel];

}
- (void)layoutSubviews{

    [super layoutSubviews];
    
    JYWeakSelf;
    CGFloat margin = 10;
    [self.searchHistoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(margin);
        make.height.mas_equalTo(20);
//        make.centerY.mas_equalTo(weakSelf);
        make.top.mas_equalTo(5);
        make.width.mas_equalTo(100);
        
    }];
    [self.searchHistoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(-margin);
        make.width.height.mas_equalTo(15);
//        make.centerY.mas_equalTo(weakSelf);
        make.top.mas_equalTo(5);
        
    }];
    
    [self.noHistoryLablel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(15);
        make.top.mas_equalTo(weakSelf.searchHistoryLabel.mas_bottom);
        make.width.mas_equalTo(Screen_Width);
        
        
        
    }];
}
- (UILabel *)searchHistoryLabel{

    if (!_searchHistoryLabel ) {
        _searchHistoryLabel = [UILabel labelText:@"历史记录" fontSize:13 textColor:k3Color textAlignment:NSTextAlignmentLeft];
    }
    return _searchHistoryLabel;

}
- (UIButton *)searchHistoryBtn{

    if (!_searchHistoryBtn) {
        UIButton *emptyButton = [[UIButton alloc] init];
        
        [emptyButton setImage:[UIImage imageNamed:@"shopping_cart_deleting"] forState:UIControlStateNormal];
        [emptyButton addTarget:self action:@selector(emptySearchHistoryDidClick) forControlEvents:UIControlEventTouchUpInside];
        
        _searchHistoryBtn = emptyButton;
    }
    return _searchHistoryBtn;
}
- (UILabel *)noHistoryLablel{

    if (!_noHistoryLablel) {
        _noHistoryLablel = [UILabel labelText:@"暂无历史搜索记录" fontSize:15 textColor:k3Color textAlignment:NSTextAlignmentCenter];
    }

    return _noHistoryLablel;
}
- (void)emptySearchHistoryDidClick{

    if (_emptySearchHistoryOnClick) {
        _emptySearchHistoryOnClick();
    }

}
@end
